<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:pkg="http://expath.org/ns/pkg"
                xmlns:web="http://expath.org/ns/webapp"
                xmlns:gae="http://fgeorges.org/ns/gae/tools"
                pkg:import-uri="http://example.org/ns/webapp/gae/datastore.xproc"
                name="pipeline"
                version="1.0">

   <p:input port="request"/>

   <p:output port="response">
      <p:pipe port="result" step="body"/>
   </p:output>

   <p:xslt name="body">
      <p:input port="source">
         <p:pipe step="pipeline" port="request"/>
      </p:input>
      <p:input port="stylesheet">
         <p:inline>
            <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                            version="2.0">
               <xsl:variable name="uri-xproc" select="'urn:x-example.org:name:xproc'"/>
               <xsl:template match="web:request">
                  <web:wrapper>
                     <web:response status="200" message="Ok">
                        <web:body content-type="application/xml"/>
                     </web:response>
                     <xsl:variable name="value" select="web:param[@name eq 'value']/@value"/>
                     <xsl:variable name="doc">
                        <value>
                           <xsl:value-of select="$value"/>
                        </value>
                     </xsl:variable>
                     <html xmlns="http://www.w3.org/1999/xhtml">
                        <head>
                           <title>Save value using Xproc</title>
                        </head>
                        <body>
                           <p>
                              <xsl:text>Received value: </xsl:text>
                              <xsl:value-of select="$value"/>
                              <xsl:text> (going to save it...)</xsl:text>
                           </p>
                           <xsl:choose>
                              <xsl:when test="gae:save($uri-xproc, $doc)">
                                 <p>Successful!</p>
                              </xsl:when>
                              <xsl:otherwise>
                                 <p>Something went wrong...</p>
                              </xsl:otherwise>
                           </xsl:choose>
                        </body>
                     </html>
                  </web:wrapper>
               </xsl:template>
            </xsl:stylesheet>
         </p:inline>
      </p:input>
      <p:input port="parameters">
         <p:empty/>
      </p:input>
   </p:xslt>

</p:declare-step>
